package ModelLayer;

import java.util.ArrayList;

public class ForestContainer {
	private ArrayList<Forest> forestList;
	
	//Singleton
	private static ForestContainer instance;
	//Constructor
	private ForestContainer(){
		
	}
	//Singleton method
	public static ForestContainer getInstance(){
		if(instance == null){
			instance = new ForestContainer();
		}
		return instance;
	}
	
	//Add forest to forestContainer
	public void addForest(Forest f){
		forestList.add(f);
	}
	//Find forest by name. Returns null if negative.
	public Forest findForest(String name){
		boolean search = false;
		int i = 0;
		Forest forest = null;
		while(!search && i < forestList.size()){
			forest = forestList.get(i);
			if(forest.getName() == name){
				search = true;
			}else{
				i++;
			}
		}
		if(search){
			return forestList.get(i);
		}else{
			return null;
		}
	}
	//Remove forest by name
	public void removeForest(String name){
		Forest forest = findForest(name);
		if(forest != null){
			forestList.remove(forest);
		}
	}
	
}
